// To parse this JSON data, do
//
//     final communityModel = communityModelFromJson(jsonString);

import 'dart:convert';

CommunityEntity communityModelFromJson(String str) =>
    CommunityEntity.fromJson(json.decode(str));

class CommunityEntity {
  CommunityEntity({
    required this.code,
    required this.msg,
    required this.obj,
  });

  int code;
  String msg;
  List<Community> obj;

  factory CommunityEntity.fromJson(Map<String, dynamic> json) =>
      CommunityEntity(
        code: json["code"],
        msg: json["msg"],
        obj: json["obj"] == null
            ? []
            : List<Community>.from(
                json["obj"].map((x) => Community.fromJson(x))),
      );
}

class Community {
  Community({
    required this.communityName,
    required this.communityId,
    this.buildings,
  });

  String communityName;
  int communityId;
  List<Building>? buildings;

  factory Community.fromJson(Map<String, dynamic> json) => Community(
        communityName: json["name"],
        communityId: json["id"],
        buildings: json["children"] == null
            ? []
            : List<Building>.from(
                json["children"].map((x) => Building.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "name": communityName,
        "id": communityId,
        "children": buildings == null
            ? []
            : List<dynamic>.from(buildings!.map((x) => x.toJson())),
      };
}

class Building {
  Building({
    required this.buildingName,
    required this.buildingId,
    this.units,
  });

  String buildingName;
  int buildingId;
  List<Unit>? units;

  factory Building.fromJson(Map<String, dynamic> json) => Building(
        buildingName: json["name"],
        buildingId: json["id"],
        units: json["children"] == null
            ? []
            : List<Unit>.from(json["children"].map((x) => Unit.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "name": buildingName,
        "id": buildingId,
        "children": units == null
            ? []
            : List<dynamic>.from(units!.map((x) => x.toJson())),
      };
}

class Unit {
  Unit({
    required this.unitName,
    required this.unitId,
    this.rooms,
  });

  String unitName;
  int unitId;
  List<Room>? rooms;

  factory Unit.fromJson(Map<String, dynamic> json) => Unit(
      unitName: json["name"],
      unitId: json["id"],
      rooms: json["children"] == null
          ? []
          : List<Room>.from(json["children"].map((x) => Room.fromJson(x))));

  Map<String, dynamic> toJson() => {
        "name": unitName,
        "children": rooms == null
            ? []
            : List<dynamic>.from(rooms!.map((x) => x.toJson())),
      };
}

class Room {
  Room({
    required this.roomName,
    required this.roomId,
  });

  String roomName;
  int roomId;

  factory Room.fromJson(Map<String, dynamic> json) => Room(
        roomName: json["name"],
        roomId: json["id"],
      );

  Map<String, dynamic> toJson() => {
        "name": roomName,
      };
}
